import { Controller, Body, Get, Post, Session, Render, HttpCode, Param,Req, Res,Ctx } from "routing-controllers";
import { config } from "../../config";
import { Service, Inject } from "typedi";
import { CarServiceImpl } from "../../service/impl/CarServiceImpl";

@Service()
@Controller(`${config.apiurl}/notify`)
export class aliPayController {
	
	@Inject()
	private carServiceImpl: CarServiceImpl;

	@HttpCode(200)
	@Post("/updateOrder")
	public async updateOrder (@Body() params: Object,
	                          @Ctx() ctx: any,
	                          @Session() session) {
	
		// 支付宝 notify_url 异步通知地址，更新订单状态，但是后端始终无法更新
		// 同样的代码 放在 return_url 通知的页面逻辑中来做可以
		await this.carServiceImpl.updateOrder(parseInt(params['out_trade_no']), (params['body'].split(","))[0]);
		return ctx.body = "success";
	}
	
}
